﻿Imports System.Collections.Generic

Namespace DoFactory.GangOfFour.Factory.RealWorld

    ''' <summary>
    ''' MainApp startup class for Real-World
    ''' Factory Method Design Pattern.
    ''' </summary>
    Public Class MainApp

        ''' <summary>
        ''' Entry point into console application.
        ''' </summary>
        Public Shared Sub Main()
            ' Note: constructors call Factory Method
            Dim documents As Document() = New Document(1) {}
            documents(0) = New [Resume]()
            documents(1) = New Report()

            ' Display document pages
            For Each document As Document In documents
                Console.WriteLine(vbLf & document.[GetType]().Name & "--")
                For Each page As Page In document.Pages
                    Console.WriteLine(" " & page.[GetType]().Name)
                Next
            Next

        End Sub

    End Class

    ''' <summary>
    ''' The 'Product' abstract class
    ''' </summary>
    MustInherit Class Page

    End Class

    ''' <summary>
    ''' A 'ConcreteProduct' class
    ''' </summary>
    Class SkillsPage
        Inherits Page

    End Class

    ''' <summary>
    ''' A 'ConcreteProduct' class
    ''' </summary>
    Class EducationPage
        Inherits Page

    End Class

    ''' <summary>
    ''' A 'ConcreteProduct' class
    ''' </summary>
    Class ExperiencePage
        Inherits Page

    End Class

    ''' <summary>
    ''' A 'ConcreteProduct' class
    ''' </summary>
    Class IntroductionPage
        Inherits Page

    End Class

    ''' <summary>
    ''' A 'ConcreteProduct' class
    ''' </summary>
    Class ResultsPage
        Inherits Page

    End Class

    ''' <summary>
    ''' A 'ConcreteProduct' class
    ''' </summary>
    Class ConclusionPage
        Inherits Page

    End Class

    ''' <summary>
    ''' A 'ConcreteProduct' class
    ''' </summary>
    Class SummaryPage
        Inherits Page

    End Class

    ''' <summary>
    ''' A 'ConcreteProduct' class
    ''' </summary>
    Class BibliographyPage
        Inherits Page

    End Class

    ''' <summary>
    ''' The 'Creator' abstract class
    ''' </summary>
    MustInherit Class Document

        Private _pages As New List(Of Page)()

        ' Constructor calls abstract Factory method
        Public Sub New()
            Me.CreatePages()
        End Sub

        Public ReadOnly Property Pages() As List(Of Page)
            Get
                Return _pages
            End Get
        End Property

        ' Factory Method
        Public MustOverride Sub CreatePages()
    End Class

    ''' <summary>
    ''' A 'ConcreteCreator' class
    ''' </summary>
    Class [Resume]
        Inherits Document

        ' Factory Method implementation
        Public Overrides Sub CreatePages()
            Pages.Add(New SkillsPage())
            Pages.Add(New EducationPage())
            Pages.Add(New ExperiencePage())
        End Sub
    End Class

    ''' <summary>
    ''' A 'ConcreteCreator' class
    ''' </summary>
    Class Report
        Inherits Document

        ' Factory Method implementation
        Public Overrides Sub CreatePages()
            Pages.Add(New IntroductionPage())
            Pages.Add(New ResultsPage())
            Pages.Add(New ConclusionPage())
            Pages.Add(New SummaryPage())
            Pages.Add(New BibliographyPage())
        End Sub

    End Class

End Namespace
